function showNewCollaboration(userId, nameUser) {
	$('#newCollaboration #userFullname').html(nameUser);
	$('#newCollaboration input[name=userId]').val(userId);

	$('#newCollaboration input[name=title]').val('');
	$('#newCollaboration input[name=message]').val('');
	$('#newCollaboration input[name=email]').val('');

	$('#newCollaboration').modal('show');
}

var GLOBAL_VOTE = null;

$('.ratings_stars').hover(
		// Handles the mouseover
		function() {
			$(this).prevAll().andSelf().addClass('icon-star');
			$(this).prevAll().andSelf().removeClass('icon-star-empty');

			$(this).nextAll().addClass('icon-star-empty');
			$(this).nextAll().removeClass('icon-star');
		},
		// Handles the mouseout
		function() {
			if (GLOBAL_VOTE == null) {
				$(this).prevAll().andSelf().removeClass('icon-star');
				$(this).prevAll().andSelf().addClass('icon-star-empty');
			} else {
				$(this).parent().children().slice(0, GLOBAL_VOTE).addClass(
						'icon-star');
				$(this).parent().children().slice(GLOBAL_VOTE).addClass(
						'icon-star-empty');
			}
			// set_votes($(this).parent());
		});

$(function() {
	$('form#feedback #comment').hide();
});

function setVote(vote) {
	$('form#feedback input[name=valuation]').val(vote);
	$('form#feedback #comment').show();
	GLOBAL_VOTE = vote;
}

function postComment() {
	var URL_POST_COMMENT = $('#sendMessageForm').attr("data-action");
	var DATA = objectifyForm($('#sendMessageForm'));
	DATA['lastMessageTS'] = $('#collaborationChat').children().first().attr(
			'data-ts');

	if (DATA['lastMessageTS'] == null || DATA['lastMessageTS'] == '')
		DATA['lastMessageTS'] = 0;

	$.ajax({
		type : 'post',
		url : URL_POST_COMMENT,
		data : DATA,
		cache : false,
		success : function(data) {
			// $('#collaborationChat').prepend(data);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log("Error: " + textStatus);
		}
	});

	$('#sendMessageForm textarea[name=message]').val('');
}

var isRefreshing = false;
function refreshChat(URL_VIEW_LAST_MESSAGE, IDCOLLABORATION) {
	var DATA = {};
	DATA['collaborationId'] = IDCOLLABORATION;
	DATA['lastMessageTS'] = $('#collaborationChat').children().first().attr(
			'data-ts');

	if (DATA['lastMessageTS'] == null || DATA['lastMessageTS'] == '')
		DATA['lastMessageTS'] = 0;

	if (!isRefreshing) {
		isRefreshing = true;
		$.ajax({
			type : 'post',
			url : URL_VIEW_LAST_MESSAGE,
			data : DATA,
			cache : false,
			success : function(data) {
				console.log(data);
				$('#collaborationChat').prepend(data);
			},
			error : function(jqXHR, textStatus, errorThrown) {
				console.log("Error: " + textStatus);
			},
			complete : function(jqXHR, textStatus) {
				isRefreshing = false;
			}
		});
	}
}

function startRefreshChat(URL_VIEW_LAST_MESSAGE, IDCOLLABORATION) {
	setInterval("refreshChat('" + URL_VIEW_LAST_MESSAGE + "', "
			+ IDCOLLABORATION + ");", 1000);
}